//
//  BottomOperationView.m
//  ProjectforHDX
//
//  Created by wusiping on 16/8/12.
//  Copyright © 2016年 H.DX. All rights reserved.
//

#import "BottomOperationView.h"

@interface BottomOperationView()

@property(nonatomic,copy) BottomOperationViewBlock clickBlock;

@end

@implementation BottomOperationView

- (id)initWithOperationArray:(NSArray *)array AndOperationType:(NSString *)type btnClick:(BottomOperationViewBlock)click{
    self=[super initWithFrame:CGRectMake(0, 0, BOUNDSWIDTH, 52)];
    if(self){
        self.clickBlock=click;
    
    //线
    [self addSoldLine:0.5 soldcolor:[UtilCheck hexStringToColor:@"e1e1df" alpha:1] pointA:CGPointMake(0, 0) pointB:CGPointMake(self.width,0)];
    
    NSArray *arr= array;
    NSInteger count=arr.count;
    CGFloat btnwidth=75;
    CGFloat btnheight=32;
    for(int i=0;i<count;i++){
        
        NSString *title=[THMangerTool operationText:[arr objectAtIndex:i]];
        NSLog(@"======================================  %@",title);

        if (![type isEqualToString:@"order"]) {
            title = [THMangerTool operationPermissions:[arr objectAtIndex:i]];
        }
        RZCustomButtom *submit=[[RZCustomButtom alloc] init];
        [submit setFrame:CGRectMake(self.width-(i+1)*(10+btnwidth) ,(self.height-btnheight)/2.f ,btnwidth,btnheight)];
        [submit setTitle:title forState:UIControlStateNormal];//确认
        
        
        submit.tag=101+[[arr objectAtIndex:i] intValue];
        [submit addRadius:5 borderwidth:1 bordercolor:[UtilCheck hexStringToColor:@"9ea7ad" alpha:1]];
        [submit setTitleColor:[UtilCheck hexStringToColor:@"9ea7ad" alpha:1]  forState:UIControlStateNormal ];
        [submit.titleLabel setFont:CustomFont(12)];
        [self addSubview:submit];
        [submit addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside ];
        
        if(i==0){
            [submit setBackgroundColor:[Toolobject getColorByRGB:26 green:86 blue:188 alpha:1]];
            [submit addRadius:5 borderwidth:1 bordercolor:[Toolobject getColorByRGB:26 green:86 blue:188 alpha:1]];

            [submit setTitleColor:[UtilCheck hexStringToColor:@"ffffff" alpha:1]  forState:UIControlStateNormal ];
        }
    }
    }
    
    return self;
}


/**
 *  按钮点击
 *sender.tag 1取消订单2修改订单，3安排发货，4确认订单，5继续发货，6确认收货，7查看物流
 *  @param sender
 */
-(void)btnClick:(RZCustomButtom*)sender{
    if(self.clickBlock){
        self.clickBlock(sender.tag - 101);
    }
 
}


@end
